<template>
  <div class="GoodsList">
    <ComSearchNav />
    <section>
      <div class="topbgc">
        <img :src="brandImg">
        <div class="topTips">
          <div class="topTipsCon">
            <span>1.0万人关注</span>
            <van-checkbox v-model="checked">
              <font v-if="!checked">关注</font>
              <font v-else>已关注</font>
              <template #icon="props">
                <img class="img-icon" :src="props.checked ? activeIcon : inactiveIcon" />
              </template>
            </van-checkbox>
          </div>
        </div>
      </div>
      <div class="topSelect">
        <ul>
          <li v-for="data in topSelect" :key="data.id">
            <span>{{data.name}}</span>
            <div class="secImg">
              <img :src="data.img" alt="">
              <div class="tbArrow">
                <b @click="upPrice">{{data.topArrow}}</b>
                <b @click="downPrice">{{data.bottomArrow}}</b>
              </div>
            </div>
          </li>
        </ul>
      </div>
      <div class="goodsList">
        <ul>
          <li v-for="data in goodsList" :key="data.id" @click="detailJump(data.gid)">
            <div class="goodsImg">
              <img :src="data.picture" alt="">
              <div class="goodsImgTips">
                <img src="../assets/goodsLists/finalPrice.png" alt="">
                <p>￥<span>{{data.nprice}}</span></p>
              </div>
            </div>
            <p class="trans">
              {{data.gname}}
            </p>
            <div class="price">
              <p class="nowPri">
                ￥<span>{{data.nprice}}</span>
              </p>
              <del class="agoPri">￥{{data.oprice}}</del>
              <img class="quan" src="../assets/goodsLists/quan.png" alt="">
            </div>
          </li>
        </ul>
      </div>
      <div class="goCart" @click="cartJump">
        <img src="../assets/goodsLists/cart.png" alt="">
      </div>
      <div class="goTop" @click="topJump" v-show="isShow">
        <img src="../assets/goodsLists/topArrow.png" alt="">
      </div>
    </section>
    <GoodsListFooter class="footer" />
  </div>
</template>

<script>
import ComSearchNav from "../components/comSearchNav";
import GoodsListFooter from "../components/goodsListFooter";
import { classifyBrand, ascGoods, descGoods } from "../utils/classify";
export default {
  name: "GoodsList",
  data() {
    return {
      brandImg: "",
      checked: false,
      isShow: false,
      activeIcon: require("../assets/goodsLists/isFocus.png"),
      inactiveIcon: require("../assets/goodsLists/unFocus.png"),
      topSelect: [
        {
          name: "综合",
          img: require("../assets/goodsLists/kong.png"),
          topArrow: " ",
          bottomArrow: " "
        },
        {
          name: "销量",
          img: require("../assets/goodsLists/kong.png"),
          topArrow: " ",
          bottomArrow: " "
        },
        {
          name: "价格",
          img: require("../assets/goodsLists/kong.png"),
          topArrow: "∧",
          bottomArrow: "∨"
        },
        {
          name: "新品",
          img: require("../assets/goodsLists/kong.png"),
          topArrow: " ",
          bottomArrow: " "
        },
        {
          name: "筛选",
          img: require("../assets/goodsLists/shaixuan.png"),
          topArrow: " ",
          bottomArrow: " "
        }
      ],
      goodsList: [
        {
          img: require("../assets/goodsLists/ia_10003.jpg"),
          finalPrice: 499,
          trans: "adidas阿迪达斯2020男子ESS DOWN VEST羽绒背心GH4583",
          nowPri: 569,
          agoPri: 899
        },
        {
          img: require("../assets/goodsLists/ia_10004.jpg"),
          finalPrice: 249,
          trans: "adidas阿迪达斯2020男子MH GFX  FT BOS针织套衫GM4477",
          nowPri: 269,
          agoPri: 399
        },
        {
          img: require("../assets/goodsLists/ia_10005.jpg"),
          finalPrice: 999,
          trans: "adidas阿迪达斯2020女子W MID DOWN COAT羽绒服GE9991",
          nowPri: 1189,
          agoPri: 1699
        },
        {
          img: require("../assets/goodsLists/ia_10006.jpg"),
          finalPrice: 169,
          trans: "adidas阿迪达斯2020男子E PLN R PNT FT针织长裤DX3684",
          nowPri: 199,
          agoPri: 329
        },
        {
          img: require("../assets/goodsLists/ia_10007.jpg"),
          finalPrice: 379,
          trans: "adidas阿迪达斯2020男子GALAXY 5PE跑步鞋FW5706",
          nowPri: 429,
          agoPri: 649
        },
        {
          img: require("../assets/goodsLists/ia_10008.jpg"),
          finalPrice: 269,
          trans: "adidas阿迪达斯2020男子UB GFX SWT针织套衫GF4003",
          nowPri: 299,
          agoPri: 289
        },
        {
          img: require("../assets/goodsLists/ia_10009.jpg"),
          finalPrice: 269,
          trans: "adidas阿迪达斯新款男子场下休闲系列篮球鞋AW3889",
          nowPri: 309,
          agoPri: 469
        }
      ]
    };
  },
  methods: {
    upPrice() {
      console.log(1);
      ascGoods({
        bid: this.$route.query.bid
      }).then(res => {
        console.log(res);
        this.goodsList = res;
      });
    },
    downPrice() {
      console.log(2);
      descGoods({
        bid: this.$route.query.bid
      }).then(res => {
        console.log(res);
        this.goodsList = res;
      });
    },
    detailJump(gid) {
      this.$router.push({ path: "/detail", query: { gid: gid } });
    },
    cartJump() {
      this.$router.push("/shoppingCart");
    },
    topJump() {
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
    },
    // 监听回到顶部按钮距浏览器顶部的距离，滚动的距离如果大于浏览器高度时，显示按钮
    scrollToTop() {
      var scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      // console.log("距离顶部的距离:" + scrollTop);
      // let browserHeight = window.outerHeight;
      if (scrollTop > 169) {
        this.isShow = true;
      } else {
        this.isShow = false;
      }
    }
  },
  // 监听滚动事件
  mounted() {
    window.addEventListener("scroll", this.scrollToTop);
  },
  destroyed() {
    // 离开该页面需要移除这个监听的事件，不然会报错
    window.removeEventListener("scroll", this.scrollToTop);
  },
  components: {
    ComSearchNav,
    GoodsListFooter
  },
  created() {
    console.log(this.$route.query.bid);
    classifyBrand({
      bid: this.$route.query.bid
    }).then(res => {
      console.log(res);
      this.goodsList = res;
    });
    this.brandImg = localStorage.getItem("brandBgc");
  }
};
</script>

<style lang="scss" scoped>
.active {
  color: red;
}
.GoodsList {
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  section {
    width: 100%;
    flex: 1;
    overflow-y: visible;
    .topbgc {
      width: 100%;
      position: relative;
      img {
        width: 100%;
      }
      .topTips {
        height: 34px;
        width: 100%;
        position: absolute;
        bottom: 0;
        .topTipsCon {
          display: flex;
          align-items: center;
          color: white;
          font-size: 14px;
          height: 100%;
          width: 45%;
          float: right;
          margin-right: 5px;
          justify-content: flex-end;
        }
      }
      .img-icon {
        width: 14px;
        height: 13px;
        margin-left: 5px;
        margin-right: -6px;
      }
      ::v-deep .van-checkbox__label {
        color: white;
      }
    }
    .topSelect {
      width: 100%;
      height: 42px;
      ul {
        width: 100%;
        height: 42px;
        display: flex;
        justify-content: space-around;
        font-size: 12px;
        color: #999;
        border-bottom: 1px solid #ccc;
        align-items: center;
        li {
          display: flex;
          .secImg {
            width: 8px;
            height: 10px;
            margin-left: 2px;
            margin-top: -5px;
            position: relative;
            img {
              width: 8px;
              height: 13px;
              margin-left: 2px;
              margin-top: 8px;
              position: absolute;
              z-index: -1;
            }
            .tbArrow {
              display: flex;
              flex-direction: column;
              position: absolute;
              top: 6px;
              z-index: 2;
              b {
                width: 12px;
                height: 8px;
                display: block;
                line-height: 8px;
                text-align: center;
              }
            }
          }
        }
      }
    }
    .goodsList {
      width: 100%;
      background-color: #f5f5f5;
      padding-bottom: 200px;
      box-sizing: border-box;
      ul {
        padding: 5px;
        background-color: #f5f5f5;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        li {
          width: 49.5%;
          height: 275px;
          background-color: white;
          margin-bottom: 5px;
          .goodsImg {
            width: 99%;
            height: 172px;
            position: relative;
            img {
              width: 100%;
              height: 172px;
            }
            .goodsImgTips {
              position: absolute;
              bottom: 3px;
              right: 5px;
              width: 50px;
              height: 50px;
              img {
                position: absolute;
                width: 50px;
                height: 50px;
              }
              p {
                width: 100%;
                position: absolute;
                color: white;
                font-weight: bold;
                bottom: 10px;
                font-size: 11px;
                text-align: center;
              }
            }
          }
          .trans {
            width: 178px;
            font-size: 12px;
            color: #666;
            height: 34px;
            text-align: left;
            padding: 0 5px;
            line-height: 16px;
            text-overflow: ellipsis;
            overflow: hidden;
          }
          .price {
            display: flex;
            height: 30px;
            align-items: center;
            margin: 5px 0 0 5px;
            .nowPri {
              width: auto;
              font-size: 14px;
              color: rgba(253, 71, 101, 1);
              font-family: PingFangSC-Medium;
              margin-right: 8px;
              span {
                margin-left: -2px;
              }
            }
            .agoPri {
              font-size: 10px;
              font-family: PingFangSC-Regular;
              font-weight: 400;
              color: rgba(153, 153, 153, 1);
              line-height: 10px;
              margin-right: 5px;
            }
            .quan {
              width: 18px;
              height: 11px;
              background-size: 100%;
              display: inline-block;
            }
          }
        }
      }
    }
    .goCart {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      position: fixed;
      right: 10px;
      bottom: 80px;
      z-index: 100;
      background-color: rgba(0, 0, 0, 0.3);
      margin-bottom: 15px;
      text-align: center;
      padding: 7.5px 0;
      box-sizing: border-box;
      img {
        width: 25px;
        height: 25px;
      }
    }
    .goTop {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      position: fixed;
      right: 10px;
      bottom: 50px;
      z-index: 100;
      background-color: rgba(0, 0, 0, 0.3);
      text-align: center;
      padding: 8.5px 0;
      box-sizing: border-box;
      img {
        width: 23px;
        height: 23px;
      }
    }
  }
  .footer {
    height: 47px;
  }
}
</style>